import numpy as np
import pandas as pd

# =====================================================
# 计算协调度D
# =====================================================
# 新型城镇化，生态环境
file = '滇中-新型城镇化与生态环境-综合水平.xlsx'
df = pd.read_excel(file, index_col=0)

df_CD = pd.DataFrame()
city_cv = df['新型城镇化']
city_en = df['生态环境']
# 计算乘积
product = city_cv * city_en
# 计算均值
mean = (city_cv + city_en) / 2
# 计算均值的平方
square_of_mean = mean * mean
# 计算耦合度
C = np.sqrt(product / square_of_mean)
# df_CD['耦合度']=C
# 计算T
T1 = 0.5 * city_cv + 0.5 * city_en
D1 = np.sqrt(C * T1)
df_CD['类型1-a2-b2'] = D1

T2 = 1 / 3 * city_cv + 2 / 3 * city_en
D2 = np.sqrt(C * T2)
df_CD['类型1-a1-b2'] = D2

T3 = 2 / 3 * city_cv + 1 / 3 * city_en
D3 = np.sqrt(C * T3)
df_CD['类型1-a2-b1'] = D3
print(df_CD)
# 保存
df_CD.to_excel('滇中-新型城镇化与生态环境-协调度.xlsx')
